package com.zw.admin.server.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zw.admin.server.page.table.PageTableRequest;
import com.zw.admin.server.page.table.PageTableHandler;
import com.zw.admin.server.page.table.PageTableResponse;
import com.zw.admin.server.service.PurchOrderItemsService;
import com.zw.admin.server.utils.HttpServletUtil;
import com.zw.admin.server.page.table.PageTableHandler.CountHandler;
import com.zw.admin.server.page.table.PageTableHandler.ListHandler;
import com.alibaba.fastjson.JSONObject;
import com.zw.admin.server.component.PurchOrderComponent;
import com.zw.admin.server.dao.PPurchOrderItemsDao;
import com.zw.admin.server.dto.ResponseInfo;
import com.zw.admin.server.model.PPurchOrderItems;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/pPurchOrderItemss")
public class PPurchOrderItemsController  {

    @Autowired
    private PPurchOrderItemsDao pPurchOrderItemsDao;

    @Autowired
    private PurchOrderItemsService purchOrderItemsService;
    
    
    @PostMapping
    @ApiOperation(value = "保存")
    public PPurchOrderItems save(@RequestBody PPurchOrderItems pPurchOrderItems) {
        pPurchOrderItemsDao.save(pPurchOrderItems);

        return pPurchOrderItems;
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据id获取")
    public PPurchOrderItems get(@PathVariable Long id) {
        return pPurchOrderItemsDao.getById(id);
    }

    @PutMapping
    @ApiOperation(value = "修改")
    public PPurchOrderItems update(@RequestBody PPurchOrderItems pPurchOrderItems) {
        pPurchOrderItemsDao.update(pPurchOrderItems);

        return pPurchOrderItems;
    }
    
    @RequestMapping(value = "/list")
    @ApiOperation(value = "列表")
    public PageTableResponse list(PageTableRequest request) {
        return new PageTableHandler(new CountHandler() {

            @Override
            public int count(PageTableRequest request) {
                return pPurchOrderItemsDao.count(request.getParams());
            }
        }, new ListHandler() {

            @Override
            public List<PPurchOrderItems> list(PageTableRequest request) {
                return pPurchOrderItemsDao.list(request.getParams(), request.getOffset(), request.getLimit());
            }
        }).handle(request);
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除")
    public void delete(@PathVariable Long id) {
        pPurchOrderItemsDao.delete(id);
    }

    @RequestMapping(value = "/itemQueryAdd", produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "查找并添加")
    public ResponseInfo itemQueryAdd(HttpServletRequest request) {
    	JSONObject requestJo = HttpServletUtil.parameterMap2Json(request);
    	
    	return purchOrderItemsService.itemQueryAdd(requestJo);
    }
    
    @PostMapping("/saveAll")
    @ApiOperation(value = "查找并添加")
    public ResponseInfo saveAll(HttpServletRequest request) {
    	JSONObject  requestJo= HttpServletUtil.parameterMap2Json(request);
    	return purchOrderItemsService.saveAll(requestJo);
    }

    
    @PostMapping("/receive")
    @ApiOperation(value = "收货")
    public ResponseInfo receive(HttpServletRequest request) {
    	JSONObject  requestJo= HttpServletUtil.parameterMap2Json(request);
    	return purchOrderItemsService.receive(requestJo);
    }
    
    
    
}
